package com.jsy.mini12306.order.service.impl;

import com.jsy.mini12306.TicketOrderService;
import com.jsy.mini12306.common.entity.TicketOrder;
import com.jsy.mini12306.common.entity.TicketOrderIterm;
import com.jsy.mini12306.order.mapper.TicketOrderMapper;
import com.jsy.mini12306.order.service.TicketOrderItermService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.function.Consumer;

/**
 * @author: SongyangJi
 * @description:
 * @since: 2021/9/7
 */

@Slf4j
@Service
@com.alibaba.dubbo.config.annotation.Service
public class TicketOrderServiceImpl implements TicketOrderService {

    @Resource
    TicketOrderMapper ticketOrderMapper;

    @Resource
    TicketOrderItermService ticketOrderItermService;

    @Transactional
    @Override
    public void saveTicketOrder(TicketOrder ticketOrder) {
        ticketOrderMapper.insert(ticketOrder);
        ticketOrder.getTicketOrderIterms().forEach(ticketOrderIterm -> {
            ticketOrderIterm.setOrderId(ticketOrder.getOrderId());
        });
        ticketOrderItermService.saveBatch(ticketOrder.getTicketOrderIterms());
    }



}
